home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK1.toast / Development Kits (Disc 1) / MacSNMP / SNMP Agents Dev Kit / Library Manager Interfaces / LibraryManagerUtilities.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-21  |  26.6 KB  |  786 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        LibraryManagerUtilities.h
  3.  
  4.     Contains:    Interface file for ASLM utilities
  5.  
  6.     Copyright:    © 1991-1993 by Apple Computer, Inc., all rights reserved.
  7.  
  8. */
  9.  
  10.  
  11. #ifndef __LIBRARYMANAGERUTILITIES__
  12. #define __LIBRARYMANAGERUTILITIES__
  13.  
  14. #ifndef __LIBRARYMANAGER__
  15. #include <LibraryManager.h>
  16. #endif
  17.  
  18. /*******************************************************************************
  19. ** Forward class declarations
  20. ********************************************************************************/
  21.  
  22. #ifdef __cplusplus
  23.     class    TNotifier;
  24.     class    TIterator;
  25.     class    TLibraryFile;
  26.     class    TFunctionSetInfo;        // same as TClassInfo
  27. #else
  28.     typedef    void    TNotifier;
  29.     typedef    void    TIterator;
  30.     typedef void    TLibraryFile;
  31.     typedef void    TFunctionSetInfo;
  32. #endif
  33.  
  34.  
  35. /*******************************************************************************
  36. ** Routines for loading and unloading the ASLM.
  37. **
  38. ** UnloadLibraryManager and LoadLibraryManager can be bad for your health! 
  39. ** They should only be used for testing purposes.
  40. ********************************************************************************/
  41.  
  42. #ifdef __cplusplus
  43.     extern "C" {
  44. #endif
  45.  
  46. Boolean    IsLibraryManagerLoaded(void);
  47. Boolean    LoadLibraryManager(void);    /* returns true if success or already loaded */
  48. void    UnloadLibraryManager(void);
  49.  
  50. /*******************************************************************************
  51. ** C Routines for allocating memory out of TMemoryPools.
  52. **
  53. ** The following routines allow C users to allocate memory from TMemoryPools.
  54. ** SLMNewOperator is used for doing allocations and SLMDeleteOperator is 
  55. ** used for freeing memory. SLMNewOperator will allocate memory out of
  56. ** the specified pool. If you pass in NULL for the pool then it will use
  57. ** default memory allocation. The default memory allocation is to allocate
  58. ** out of the the library's local pool if the library was built with
  59. ** memory=local, and out of the client's local pool if the library was built
  60. ** with memory=client. If you don't want to use default memory allocation then
  61. ** you can call GetLocalPool to get the library's local pool, and GetClientPool
  62. ** to get the current client's local pool.
  63. ********************************************************************************/
  64.  
  65. void*    SLMNewOperator(size_t, TMemoryPool*);
  66. void    SLMDeleteOperator(void*);
  67.  
  68. /*******************************************************************************
  69. ** GetSLMVersion
  70. **
  71. ** Returns the version of the installed ASLM in the 'vers'
  72. ** resource format (the first 4 bytes only). Returns 0 if the
  73. ** ASLM is not installed.
  74. ********************************************************************************/
  75.  
  76. unsigned long GetSLMVersion(void);
  77.  
  78. /*******************************************************************************
  79. ** RegisterInspector
  80. **
  81. ** Should only be used by Inspector application.
  82. ********************************************************************************/
  83.  
  84. void RegisterInspector(void*);
  85.  
  86. /*******************************************************************************
  87. ** Trace
  88. **
  89. ** Used to send output to the Trace Montior's Window.
  90. ********************************************************************************/
  91.  
  92. void Trace(const char *formatStr, ...);
  93.  
  94. /*******************************************************************************
  95. ** SLMsprintf
  96. **
  97. ** The SLMsprintf routine in stdclib.o won't work with ASLM libraries.
  98. ** Use the one in LibraryManager.o instead.
  99. ********************************************************************************/
  100.  
  101. int SLMsprintf(char *outString, const char *argp, ...);                
  102.  
  103. /*******************************************************************************
  104. ** Utility functions
  105. **
  106. ** %%% These functions need to be modified if unsigned short is not 16 bits
  107. ********************************************************************************/
  108.  
  109. #ifdef __cplusplus
  110.  
  111. inline unsigned short HighWord(unsigned long l)
  112. {
  113.     return ((unsigned short)(l >> 16));
  114. }
  115.  
  116. inline unsigned short LowWord(unsigned long l)
  117. {
  118.     return (unsigned short)l;
  119. }
  120.  
  121. inline unsigned char HighByte(unsigned short l)
  122. {
  123.     return (unsigned char)(l >> 8);
  124. }
  125.  
  126. inline unsigned char LowByte(unsigned short l)
  127. {
  128.     return (unsigned char)l;
  129. }
  130.  
  131. #else
  132.  
  133. #define HighWord(x)        ((unsigned short)((x) >> 16))
  134. #define LowWord(x)        (((unsigned short)(x)))
  135. #define HighByte(x)        ((unsigned char)((x) >> 8))
  136. #define LowByte(x)        (((unsigned char)(x)))
  137.  
  138. #endif
  139.  
  140. /*******************************************************************************
  141. ** Atomic Bit functions
  142. **
  143. ** These functions atomically set and clear bits, and return what value the
  144. ** bit previously had
  145. ********************************************************************************/
  146.  
  147. #if USES68KINLINES
  148.  
  149.     #pragma parameter __D0 AtomicSetBoolean(__A0)
  150.     Boolean AtomicSetBoolean(unsigned char*) =
  151.     {
  152.         0x08d0, 0x00, 0x57c0    /* bset.b #0,(a0); seq d0 */
  153.     };
  154.     
  155.     #pragma parameter __D0 AtomicClearBoolean(__A0)
  156.     Boolean AtomicClearBoolean(unsigned char*) =
  157.     {
  158.         0x0890, 0x00, 0x56c0    /* bclr.b #0,(a0); sne d0 */
  159.     };
  160.     
  161.     #pragma parameter __D0 AtomicTestBoolean(__A0)
  162.     Boolean AtomicTestBoolean(unsigned char*) =
  163.     {
  164.         0x0810, 0x00, 0x57c0    /* btst.b #0,(a0); seq d0 */
  165.     };
  166.     
  167. #endif
  168.  
  169. Boolean    AtomicSetBoolean(unsigned char*);
  170. Boolean    AtomicClearBoolean(unsigned char*);
  171. Boolean    AtomicTestBoolean(unsigned char*);
  172. Boolean    SetBit(void* mem, size_t bitno);
  173. Boolean    ClearBit(void* mem, size_t bitno);
  174. Boolean    TestBit(const void* mem, size_t bitno);
  175.  
  176. /******************************************************************************
  177. ** Memory Functions
  178. **
  179. ** SLMmemcpy, SLMmemmove, and SLMmemset are equivalent to the C memcpy, memmove,
  180. ** and memset routines. They are exported by SLM and are faster then the C versions.
  181. *******************************************************************************/
  182.  
  183. void    ZeroMem(void* dest, size_t nBytes);
  184. void*     SLMmemcpy(void* dest, const void* src, size_t nBytes);
  185. void*     SLMmemmove(void* dest, const void* src, size_t nBytes);
  186. void*    SLMmemset (void *dest, int c, size_t n);
  187.  
  188. /**********************************************************************
  189. ** struct TFileSpec
  190. **
  191. ** TFileSpec is a struct for specifying the location of a library
  192. ** file (TLibraryFile) in a file system or OS independent way. The 
  193. ** "subclasses" contain the details and the "base class" is used to compare
  194. ** them or to pass them around without worry about the contents.
  195. **
  196. ** Currently only the TMacFileSpec is supported since this is how the
  197. ** SLM tracks library files on the Mac OS. There is a chance that in the
  198. ** furture it may track files under System 7.0 using TFileIDFileSpec so
  199. ** you should write your 7.0 code to handle either type. The
  200. ** IsFileSpecTypeSupported() routine will tell you if the specified
  201. ** TFileSpec subclass is supported.
  202. **
  203. ** Generally you don't need to be concerned with with TFileSpecs unless
  204. ** you are going to call RegisterLibraryFile(), RegisterLibraryFileFolder(),
  205. ** or GetFileSpec().
  206. ***********************************************************************/
  207.  
  208. /* Different types of TFileSpecs we can have. */
  209.  
  210. #ifndef __cplusplus
  211.  
  212. typedef unsigned int    FileSpecType;
  213.  
  214. #define kUnknownType    ((FileSpecType)0)
  215. #define kMacType        ((FileSpecType)1)
  216. #define kFileIDType        ((FileSpecType)2)
  217. #define kImageType        ((FileSpecType)3)
  218. #define kMacRomType        ((FileSpecType)9)
  219. #define kMaxType        ((FileSpecType)255)
  220.  
  221. Boolean IsFileSpecTypeSupported(FileSpecType);
  222. Boolean CompareFileSpecs(const void* f1, const void* f2);
  223.  
  224. struct TFileSpec
  225. {
  226.     unsigned char    fType;        /* FileSpectype */
  227.     unsigned char    fSize;        /* size of struct */
  228. };
  229. typedef struct TFileSpec TFileSpec;
  230.  
  231. /**********************************************************************
  232. ** struct TMacFileSpec
  233. **
  234. ** TMacFileSpec keeps track of the file by using an file name, volume
  235. ** refNum, and directory id. You must use InitMacFileSpec to make
  236. ** sure that the length is set properly.
  237. ***********************************************************************/
  238.  
  239. struct TMacFileSpec
  240. {
  241.     unsigned char    fType;        /* FileSpec type                        */
  242.     unsigned char    fSize;        /* size of struct                        */
  243.     short            fVRefNum;    /* volume refNum of volume file is on    */
  244.     long            fParID;        /* dirID of the folder file is in        */
  245.     Str63            fName;        /* name of the file                        */
  246. };        
  247. typedef struct TMacFileSpec TMacFileSpec;
  248.     
  249. void InitMacFileSpec(TMacFileSpec *spec, int vRefNum, long parID, Str63 name);
  250.  
  251. /**********************************************************************
  252. ** struct TFileIDFileSpec
  253. **
  254. ** TFileIDFileSpec keeps track of library files by fileID and vRefNum.
  255. ** You must use InitFileIDFileSpec to make sure that the length is set
  256. ** properly
  257. ***********************************************************************/
  258.  
  259. /* Some macros to make accessing fields without doing a cast easier */
  260. #define GetFileIDFromFileSpec(x)    (((const TFileIDFileSpec*)x)->fFileID)
  261. #define GetVRefNumFromFileSpec(x)    (((const TFileIDFileSpec*)x)->fVRefNum)
  262.  
  263. struct TFileIDFileSpec
  264. {
  265.     unsigned char    fType;        /* FileSpec type    */
  266.     unsigned char    fSize;        /* size of struct    */
  267.     short            fVRefNum;    /* volume refNum    */
  268.     long            fFileID;    /* FileID            */
  269. };
  270. typedef struct TFileIDFileSpec TFileIDFileSpec;
  271.  
  272. void InitFileIDFileSpec(TFileIDFileSpec *spec, int vRefNum, long fileID);
  273.  
  274. #endif
  275.  
  276. /*******************************************************************************
  277. ** RegisterLibraryFile/UnregisterLibraryFile
  278. **
  279. ** Used to register or unregister a library file. Currently only the
  280. ** TMacFileSpec is supported. You'll get a kNotSupported error for anything else.
  281. **
  282. ** RegisterLibraryFile returns kNoError if successful or kFileNotFound if
  283. ** an error ocurred while trying to access the file. Other error codes are also
  284. ** possible if there was trouble processing the file such as kOutOfMemory. If
  285. ** created the TLibraryFile is returned in the TLibraryFile** parameter. You
  286. ** can pass in null if you don't want the value returned.
  287. **
  288. ** UnregisterLibraryFile accepts a "forceUnload" parameter. If true is passed
  289. ** then it will force all loaded libraries in the library file to be
  290. ** unloaded even if they are in use. Unless you are sure that loaded libraries
  291. ** can be safely unloaded you should pass false. In this case the library file
  292. ** will not be deleted until all of its libraries are unloaded.
  293. ** kNoError will be returned if successful and wil be returend kNotSupported if
  294. ** the folder was never registered.
  295. ********************************************************************************/
  296.  
  297. OSErr    RegisterLibraryFile(const TFileSpec*, TLibraryFile**);
  298. OSErr    UnregisterLibraryFile(TLibraryFile*, BooleanParm forceUnload);
  299. OSErr    UnregisterLibraryFileByFileSpec(const TFileSpec*, BooleanParm forceUnload);
  300.  
  301. /*******************************************************************************
  302. ** RegisterLibraryFileFolder/UnregisterLibraryFileFolder
  303. **
  304. ** Used to register a folder that contains library files in it. The SLM will keep
  305. ** track of library files dragged into and out of this folder. Currently only the
  306. ** TMacFileSpec is supported. You'll get a kNotSupported error for anything else.
  307. **
  308. ** RegisterLibraryFileFolder returns kNoError if successful or kFileNotFound if
  309. ** an error ocurred while trying to access the folder.
  310. **
  311. ** UnregisterLibraryFileFolder accepts a "forceUnload" parameter. If true is passed
  312. ** then it will unregister the folder and force all loaded libraries to be
  313. ** unloaded even if they are in use. Unless you are sure that loaded libraries
  314. ** can be safely unloaded you should pass false. kNoError will be returned if
  315. ** successful, kFolderNotFound if the folder was never registered, and
  316. ** kFolderInUse if any libraries in the folder were loaded and false was passed
  317. ** in the forceUnload parameter.
  318. ********************************************************************************/
  319.  
  320. OSErr    RegisterLibraryFileFolder(const TFileSpec*);
  321. OSErr    UnregisterLibraryFileFolder(const TFileSpec*, BooleanParm forceUnload);
  322.  
  323. /*******************************************************************************
  324. ** EnterSystemMode/LeaveSystemMode
  325. **
  326. ** These functions should bracket calls that open files or get memory that needs
  327. ** to hang around after an application quits
  328. ********************************************************************************/
  329.  
  330. void*    EnterSystemMode(void);
  331. void    LeaveSystemMode(void*);
  332.  
  333. /*******************************************************************************
  334. ** Death Notification
  335. ********************************************************************************/
  336.  
  337. Boolean InstallDeathWatcher(TNotifier* notifier);
  338. Boolean RemoveDeathWatcher(TNotifier* notifier);
  339.  
  340. /*******************************************************************************
  341. ** EnterInterrupt/LeaveInterrupt
  342. **
  343. ** These functions should be called when you are in an interrupt service routine
  344. ** or a deferred task and you want to do something that will cause ASLM
  345. ** code to be executed such as allocating pool memory or newing an object. The
  346. ** ASLM needs to know that it is at interrupt time so it doesn't do
  347. ** anything stupid like try to allocate memory or load library code. This doesn't
  348. ** mean that all ASLM calls are safe at interrupt time, just that the
  349. ** ones that claim to be safe will only be safe if you do an EnterInterrupt call
  350. ** first.
  351. **
  352. ** You don't need to use these routines when your interrupt service routine is
  353. ** scheduling an operation on a TInterruptScheduler, when the operation gets
  354. ** executed at deferred task time, or when a TTimeScheduler operation gets
  355. ** executed. In the former case the ASLM is smart enough to realize
  356. ** that you are at interrupt time and in the later two cases the
  357. ** ASLM does an EnterInterrupt before calling your operation and a
  358. ** LeaveInterrupt when your operation returns.
  359. ********************************************************************************/
  360.  
  361. void    EnterInterrupt(void);
  362. void    LeaveInterrupt(void);
  363.  
  364. /*******************************************************************************
  365. ** AtInterruptLevel
  366. **
  367. ** This function returns true if we are currently executing at non-system-task
  368. ** time.
  369. ********************************************************************************/
  370.  
  371. Boolean AtInterruptLevel(void);
  372.  
  373. /*******************************************************************************
  374. ** InInterruptScheduler
  375. **
  376. ** This function returns true if we are currently running an interrupt scheduler
  377. ********************************************************************************/
  378.  
  379. Boolean InInterruptScheduler(void);
  380.  
  381. /**********************************************************************
  382. ** GlobalWorld routines
  383. **
  384. ** InitGlobalWorld will create and initialize the global world for
  385. ** standalone code on the MacOS such as INITs and CDEVs. It also does
  386. ** a SetCurrentGlobalWorld. FreeGlobalWorld will free the memory used
  387. ** by the global world created by InitGlobalWorld.
  388. **
  389. ** EnterCodeResource is also used by stand alone code resources. It is
  390. ** most useful when the code resource only calls InitLibraryManager once
  391. ** but may then be reentered multiple times before calling CleanupLibraryManager.
  392. ** EnterCodeResoruce will set the current global world to the code resources
  393. ** global world and set the code resource as the current client.
  394. ** LeaveCodeResource will undo what EnterCodeResource does. These routines
  395. ** are NOT reentrant. You must call InitCodeResource before calling
  396. ** EnterCodeResource. It will call InitGlobalWorld and save the global world
  397. ** pointer in a PC-relative location so EnterCodeResource can access it.
  398. **
  399. ** SetCurrentGlobalWorld and GetCurrentGlobalWorld used for getting and
  400. ** setting A5 on the MacOS.
  401. **
  402. ** GetGlobalWorld is used to get the global world pointer for a Library.
  403. ** OpenGlobalWorld will make the library's global world the current global
  404. ** world. It's the same as calling SetCurrentGlobalWorld(GetGlobalWorld()).
  405. ** CloseGlobalWorld is used to revert back to the global world that was
  406. ** current before calling OpenGlobalWorld. It's the same as calling
  407. ** SetCurrentGlobalWorld(oldWorld) except that it doesn't return a
  408. ** global world.
  409. **
  410. ** Since libraries are always compiled with model far, it's
  411. ** not necessary to do an OpenGlobalWorld before accessing globals or
  412. ** making intersegment calls. Their only purpose is to make the library
  413. ** the current "Client" since the client is determined by the current
  414. ** value of A5 on the MacOS.
  415. **
  416. ** ONLY LIBRARIES AND MODEL FAR CLIENTS SHOULD CALL Get/Open/CloseGlobalWorld.
  417. ********************************************************************************/
  418.  
  419.  
  420. #if USES68KINLINES
  421. #pragma parameter __D0 SetCurrentGlobalWorld(__A0)
  422. GlobalWorld SetCurrentGlobalWorld(GlobalWorld newWorld)
  423.     = {0x200D,                        /* move.l    A5,D0        */
  424.        0x2A48};                        /* move.l    A0,A5        */
  425.        
  426. GlobalWorld GetCurrentGlobalWorld()
  427.     = {0x200D};                        /* move.l    A5,D0        */
  428. #endif
  429.  
  430.  
  431. OSErr                InitGlobalWorld(void);        /* called by standalone code only!!! */
  432. void                FreeGlobalWorld(void);        /* called by standalone code only!!! */
  433.  
  434. OSErr                InitCodeResource(void);        /* called by standalone code only!!! */
  435. void                EnterCodeResource(void);    /* called by standalone code only!!! */
  436. void                LeaveCodeResource(void);    /* called by standalone code only!!! */
  437.     
  438. TLibraryManager*    GetCurrentClient(void);
  439. TLibraryManager*    SetCurrentClient(TLibraryManager*);
  440. TLibraryManager*    SetSelfAsClient(void);    /* set owner of code making call as current client */
  441. TLibraryManager*    SetClientToWorld(void);    /* set owner of current global world as current client */
  442.  
  443. GlobalWorld        SetCurrentGlobalWorld(GlobalWorld newWorld);
  444. GlobalWorld        GetCurrentGlobalWorld(void);
  445.     
  446. GlobalWorld     GetGlobalWorld(void);
  447. GlobalWorld        OpenGlobalWorld(void);
  448. void            CloseGlobalWorld(GlobalWorld oldWorld);
  449.  
  450. /*    -------------------------------------------------------------------------
  451.     Inline implementation for global world functions
  452.     ------------------------------------------------------------------------- */
  453.  
  454. #ifdef __cplusplus
  455.     inline GlobalWorld GetGlobalWorld()
  456.     {
  457.         return GetLocalLibraryManager()->GetGlobalWorld();
  458.     }
  459.     inline GlobalWorld OpenGlobalWorld()
  460.     {
  461.         return SetCurrentGlobalWorld(GetGlobalWorld());
  462.     }
  463.     inline void    CloseGlobalWorld(GlobalWorld oldWorld)
  464.     {
  465.         SetCurrentGlobalWorld(oldWorld);
  466.     }
  467. #else
  468.     #define GetGlobalWorld()        ((GlobalWorld)(((void**)GetLocalLibraryManager())[4]))
  469.     #define OpenGlobalWorld()        SetCurrentGlobalWorld(GetGlobalWorld())
  470.     #define CloseGlobalWorld(world)    SetCurrentGlobalWorld(world)
  471. #endif
  472.  
  473. /**********************************************************************
  474. ** TLibraryFile "C" interface
  475. **
  476. ** The C interface to the TLibraryFile class defined in 
  477. ** LibraryManagerClasses.h. Used mainly to get resources out of a library.
  478. ********************************************************************************/
  479.  
  480. TLibraryFile*    GetLocalLibraryFile();
  481.  
  482. Ptr            GetSharedResource(TLibraryFile*, ResType, int theID, OSErr*);
  483. Ptr            GetSharedIndResource(TLibraryFile*, ResType, int index, OSErr*);
  484. Ptr            GetSharedNamedResource(TLibraryFile*, ResType,
  485.                                    const char* name, OSErr*);
  486.  
  487. void        ReleaseSharedResource(TLibraryFile*, Ptr);
  488. long        CountSharedResources(TLibraryFile*, ResType);
  489.  
  490. size_t        GetSharedResourceUseCount(TLibraryFile*, Ptr);
  491. OSErr        GetSharedResourceInfo(TLibraryFile*, Ptr, size_t* theSize,
  492.                                   short* theID, ResType*, char* theName);
  493.  
  494. TFileSpec*    GetFileSpec(TLibraryFile*);
  495. long        GetRefNum(TLibraryFile*);
  496.  
  497. OSErr        OpenLibraryFile(TLibraryFile*);
  498. OSErr        CloseLibraryFile(TLibraryFile*);
  499.         
  500. OSErr        Preflight(TLibraryFile*, long* savedRefNum);
  501. OSErr        Postflight(TLibraryFile*, long savedRefNum);
  502.  
  503. /**********************************************************************
  504. ** TLibrary "C" interface
  505. **
  506. ** The C interface to the TLibrary class. Used mainly to manipulate
  507. ** code segments in a library.
  508. ***********************************************************************/
  509.  
  510. TLibraryFile*    GetLibraryFile(TLibrary*);
  511.  
  512. OSErr    LoadCodeSegmentByNumber(TLibrary*, int segmentNumber);
  513. OSErr    LoadCodeSegmentByName(TLibrary*, ProcPtr theRoutine);
  514. OSErr    UnloadCodeSegmentByNumber(TLibrary*, int segmentNumber);
  515. OSErr    UnloadCodeSegmentByName(TLibrary*, ProcPtr theRoutine);
  516.  
  517. /*********************************************************************
  518. ** Routines that will get a TLibrary object
  519. **********************************************************************/
  520.  
  521. #ifdef __cplusplus
  522.  
  523. TLibrary*    GetLocalLibrary();
  524. TLibrary*    LookupLibrary(const TLibraryID&);
  525. TLibrary*    LookupLibraryWithClassID(const TClassID&);
  526. TLibrary*    LookupLibraryWithFunctionSetID(const TFunctionSetID&);
  527.  
  528. #else
  529.     
  530. TLibrary*    GetLocalLibrary();
  531. TLibrary*    LookupLibrary(const TLibraryID);
  532. TLibrary*    LookupLibraryWithClassID(const TClassID);
  533. TLibrary*    LookupLibraryWithFunctionSetID(const TFunctionSetID);
  534.  
  535. #endif
  536.  
  537. /*********************************************************************
  538. ** These routines are experimental. They were not tested for ASLM 1.1.1,
  539. ** but will be for the next release. If they work ok for you then feel
  540. ** free to use them.
  541. ** 
  542. ** CreateLibraryIterator returns an iterator that will iterate over all
  543. ** publicly known libraries and CreateLibraryFileIterator will return
  544. ** an iterator that will iterate over all publicly known library files.
  545. ** Make sure you delete the iterator when you are done. GetLibraryID
  546. ** return the library ID for a shared library. It is useful when used
  547. ** in conjunction with CreateLibraryIterator.
  548. **********************************************************************/
  549.  
  550. TIterator* CreateLibraryIterator(TLibraryManager* mgr);
  551. TIterator* CreateLibraryFileIterator(TLibraryManager* mgr);
  552.  
  553. #ifdef __cplusplus
  554.     TLibraryID* GetLibraryID(TLibrary*);
  555. #else
  556.     TLibraryID GetLibraryID(TLibrary*);
  557. #endif
  558.  
  559. /*********************************************************************
  560. ** Per Client data routines
  561. **********************************************************************/
  562.  
  563. void*    GetClientData(void);
  564. void*    GetLibraryClientData(TLibrary*);
  565.  
  566. /**********************************************************************
  567. ** TClassInfo "C" interface
  568. **
  569. ** The C interface to the TClassInfo class. Used mainly to get information
  570. ** about function sets. It is most useful for iterating over all function sets
  571. ** with a common interface. This can be done by giving the functions sets the
  572. ** same "parent id" when exporting each function set.
  573. **
  574. ** Note, TClassInfo can also be used to iterate over function sets and
  575. ** the routines given below can also be used iterate over classes.
  576. ***********************************************************************/
  577.  
  578. #ifdef __cplusplus
  579.  
  580. TFunctionSetInfo*    GetFunctionSetInfo(const TFunctionSetID&, OSErr* = NULL);
  581. void                FreeFunctionSetInfo(TFunctionSetInfo*);
  582.  
  583. void                FSInfoReset(TFunctionSetInfo*);        // start iteration over
  584. TFunctionSetID*        FSInfoNext(TFunctionSetInfo*);        // get next function set
  585. Boolean                FSInfoIterationComplete(TFunctionSetInfo*);    // true if we are done iterating
  586.  
  587. TFunctionSetID*        FSInfoGetFunctionSetID(TFunctionSetInfo*);
  588. TFunctionSetID*        FSInfoGetParentID(TFunctionSetInfo*, size_t idx = 0);
  589. TLibrary*            FSInfoGetLibrary(TFunctionSetInfo*);
  590. TLibraryFile*        FSInfoGetLibraryFile(TFunctionSetInfo*);
  591. unsigned short        FSInfoGetVersion(TFunctionSetInfo*);
  592. unsigned short        FSInfoGetMinVersion(TFunctionSetInfo*);
  593.  
  594. #else
  595.  
  596. TFunctionSetInfo*    GetFunctionSetInfo(TFunctionSetID, OSErr*);
  597. void                FreeFunctionSetInfo(TFunctionSetInfo*);
  598.  
  599. void                FSInfoReset(TFunctionSetInfo*);        /* start iteration over */
  600. TFunctionSetID        FSInfoNext(TFunctionSetInfo*);        /* get next function set */
  601. Boolean                FSInfoIterationComplete(TFunctionSetInfo*);    /* true if we are done iterating */
  602.  
  603. TFunctionSetID        FSInfoGetFunctionSetID(TFunctionSetInfo*);
  604. TFunctionSetID        FSInfoGetParentID(TFunctionSetInfo*, size_t idx);
  605. TLibrary*            FSInfoGetLibrary(TFunctionSetInfo*);
  606. TLibraryFile*        FSInfoGetLibraryFile(TFunctionSetInfo*);
  607. unsigned short        FSInfoGetVersion(TFunctionSetInfo*);
  608. unsigned short        FSInfoGetMinVersion(TFunctionSetInfo*);
  609.  
  610. #endif
  611.  
  612. /*******************************************************************************
  613. ** Debugging Macros and inlines
  614. ********************************************************************************/
  615.  
  616. void DebugBreakProc(BooleanParm, const char*);
  617.  
  618. #ifdef __cplusplus
  619. };
  620.  
  621. inline void DoDebugBreak(BooleanParm value, const char* str)
  622. {
  623.     DebugBreakProc(value, str);
  624. }
  625.  
  626. inline void DoDebugBreak(const char* str)
  627. {
  628.     DebugBreakProc(true, str);
  629. }
  630.  
  631.  
  632. #define ForceDebugBreak(str)        DoDebugBreak(true, str)
  633.  
  634. #if qDebug
  635.     #define DebugBreak(str)            DoDebugBreak(true, str)
  636.     #define DebugTest(val, str)        DoDebugBreak(val, str)
  637. #else
  638.     #define DebugBreak(str)
  639.     #define DebugTest(val, str)
  640. #endif
  641.  
  642. #else
  643.  
  644. #if qDebug
  645.     #define DebugBreak(str)            DebugBreakProc(true, str)
  646.     #define DebugTest(val, str)        DebugBreakProc(val, str)
  647. #else
  648.     #define DebugBreak(str)
  649.     #define DebugTest(val, str)
  650. #endif
  651.  
  652. #endif
  653.  
  654. /*******************************************************************************
  655. ** TAtomicBoolean
  656. **
  657. ** Set returns true if you were the "setter".
  658. ** Clear returns true if you were the "clearer".
  659. ** Test returns the current state of the boolean.
  660. ********************************************************************************/
  661.  
  662. #ifdef __cplusplus
  663.  
  664. struct TAtomicBoolean
  665. {
  666.         void        Init();
  667.         Boolean        Set();
  668.         Boolean        Clear();
  669.         Boolean        Test();
  670.         
  671.     unsigned char    fFlag;
  672. };
  673.  
  674.     inline void TAtomicBoolean::Init()
  675.     {
  676.         fFlag = 0;
  677.     }
  678.  
  679.     inline Boolean TAtomicBoolean::Set()
  680.     {
  681.         return AtomicSetBoolean(&fFlag);
  682.     }
  683.  
  684.     inline Boolean TAtomicBoolean::Clear()
  685.     {
  686.         return AtomicClearBoolean(&fFlag);
  687.     }
  688.     
  689.     inline Boolean TAtomicBoolean::Test()
  690.     {
  691.         return AtomicTestBoolean(&fFlag);
  692.     }
  693.  
  694. #endif    
  695.  
  696. /*******************************************************************************
  697. ** TUseCount
  698. ********************************************************************************/
  699.  
  700. #ifdef __cplusplus
  701.  
  702. #if USES68KINLINES
  703.  
  704. #pragma parameter __D0 IncrementUseCount(__A0)
  705. extern "C" Boolean IncrementUseCount(long*) =
  706. {
  707.     0x5290,        /*    addq.l    #1,(a0)    */
  708.     0x57c0        /*  seq        d0        */
  709. };
  710.  
  711. #pragma parameter __D0 DecrementUseCount(__A0)
  712. extern "C" Boolean DecrementUseCount(long*) =
  713. {
  714.     0x5390,        /*    subq.l    #1,(a0)    */
  715.     0x5bc0        /*  smi        d0        */
  716. };
  717.  
  718. #else
  719.  
  720. extern "C" Boolean IncrementUseCount(long*);
  721. extern "C" Boolean DecrementUseCount(long*);
  722.  
  723. #endif
  724.  
  725. struct TUseCount
  726. {
  727.         void        SetValue(long);
  728.         void        SetUseCount(long);
  729.         long        GetValue() const;
  730.         long        GetUseCount() const;
  731.         void        Init();
  732.         Boolean        Increment();        // Returns True if first time
  733.         Boolean        Decrement();        // Returns True if back to unused
  734.         Boolean        IsUnused() const;
  735.         
  736.     long    fValue;
  737. };
  738.  
  739. /*    -------------------------------------------------------------------------
  740.     Inline methods for TUseCount
  741.     ------------------------------------------------------------------------- */
  742.  
  743.     inline void TUseCount::SetValue(long val)
  744.     {
  745.         fValue = val;
  746.     }
  747.     
  748.     inline void TUseCount::SetUseCount(long val)
  749.     {
  750.         fValue = val - 1;
  751.     }
  752.     
  753.     inline void TUseCount::Init()
  754.     {
  755.         fValue = -1;
  756.     }
  757.     
  758.     inline Boolean TUseCount::IsUnused() const
  759.     {
  760.         return fValue < 0;
  761.     }
  762.     
  763.     inline long TUseCount::GetValue() const
  764.     {
  765.         return fValue;
  766.     }
  767.     
  768.     inline long TUseCount::GetUseCount() const
  769.     {
  770.         return fValue + 1;
  771.     }
  772.     
  773.     inline Boolean TUseCount::Increment()
  774.     {
  775.         return IncrementUseCount(&fValue);
  776.     }
  777.     
  778.     inline Boolean TUseCount::Decrement()
  779.     {
  780.         return DecrementUseCount(&fValue);
  781.     }
  782.     
  783. #endif    
  784.  
  785. #endif
  786.